#ifndef __CHANNEL_HPP__
#define __CHANNEL_HPP__
#include <iostream>
#include<unistd.h>
using namespace std;

class Channel
{
public:
    Channel(int wfd, string name, pid_t who)
        : _wfd(wfd)
        ,_who(who)
    {
        _name = "Channel-" + std::to_string(wfd) + "-" + std::to_string(who);
    }
    string Name()
    {
     return _name;
    }

    void Send(int cmd)
    {
        write(_wfd,&cmd,sizeof(cmd));
    }
    pid_t Id()
    {
        return _who;
    }


    void Close()//因为管道只要写端关闭，读端读完缓存区里的东西，就会自动关闭
    {
      close(_wfd);
    }

private:
    int _wfd;//这是管道的写端
    string _name;
    pid_t _who;
};

#endif